package com.emm.yixun.openapi.hander;

import com.emm.yixun.common.app.AddCustomerIntentionReqDto;
import com.emm.yixun.common.app.AddCustomerIntentionResDto;
import com.emm.yixun.common.app.CustomerCommDto;
import com.emm.yixun.common.exception.XFUNExceptionCode;
import com.emm.yixun.config.CustomerUtil;
import com.emm.yixun.customer.service.app.CustomerServiceAppFacade;
import com.emm.yixun.openapi.dto.base.BaseRequestDTO;
import com.emm.yixun.openapi.dto.base.BaseResponseDTO;
import com.emm.yixun.openapi.hander.base.CommonAbstractHander;
import com.emm.yixun.openapi.vo.AddCustomerIntentionReqVo;
import net.sf.ehcache.CacheManager;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;

/**
 * 新增客户
 * @author Administrator
 *
 */
@Service("addCustomerIntention")
public class AddCustomerIntentionHander extends CommonAbstractHander{
	
	@Autowired
	private CustomerServiceAppFacade customerServiceAppFacade;
	@Autowired
	private CacheManager cacheManager;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		AddCustomerIntentionReqVo req = (AddCustomerIntentionReqVo)reqDto;
		AddCustomerIntentionReqDto reqDto1 = req.getParams();
		CustomerCommDto dto =  CustomerUtil.checkIntentionLevel(reqDto1);
		reqDto1.setIsIntentionIntact(dto.getIsIntentionIntact());
      	reqDto1.setIntentionLevel(dto.getIntentionLevel());
		BaseResponseDTO<AddCustomerIntentionResDto> res = new BaseResponseDTO<AddCustomerIntentionResDto>();
		AddCustomerIntentionResDto resDto = new AddCustomerIntentionResDto();
		try{
			resDto = customerServiceAppFacade.addCustomerIntention(reqDto1);
		} catch (Exception e) {
			if("customer".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("新增客户操作失败");
				resDto.setResult("0");
			}else if("houseType".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("关注户型操作失败");
				resDto.setResult("0");
			}else if("premises".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("意向组团操作失败");
				resDto.setResult("0");
			}else if("room".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("意向房号操作失败");
				resDto.setResult("0");
			}else if("family".equals(e.getMessage())){
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg("家庭成员操作失败");
				resDto.setResult("0");
			}else{
				resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
				resDto.setErrorMsg(XFUNExceptionCode.UNKNOW_EXCEPTON.getDesout());
				resDto.setResult("0");
			}
		}
		res.setResData(resDto);
		return res;
	}
}
